/*
 * Thread.cpp
 *
 *  Created on: Oct 26, 2012
 *      Author: lucas
 */

#include "Thread.h"

#include <iostream>
Thread::Thread() {
	isRunning = false;
}

void Thread::iniciar() {
	int ret;
	isRunning = true;
	ret = pthread_create(&t, NULL, Thread::rutina, this);
	if (ret)
		isRunning = false;
}

void Thread::join() {
	pthread_join(t, NULL);
}

void* Thread::rutina(void* p) {
	Thread* t = (Thread*)p;
	t->run();
	return NULL;
}

bool Thread::running() {
	bool ret;
	ret = isRunning;
	return ret;
}

void Thread::run() {
	this->ejecutar();
	isRunning = false;
	pthread_exit(NULL);
}

void Thread::parar() {
	isRunning = false;
}

Thread::~Thread() {
}
